<template>
	<view style="margin-top: 100rpx;" >


		<view class="gui-flex gui-row gui-nowrap gui-justify-content-center gui-margin-top">
			<view class="other-login-icons" hover-class="gui-tap">
				<!-- <text class="other-login-icons gui-icons gui-color-blue" style="font-size: 100rpx;">&#xe63e;</text> -->
				<image src="/static/images/logo.png" style="width: 300rpx;height:300rpx;border-radius: 50%;" mode="aspectFit" class="" ></image>
			</view>
		</view>
		<view class="gui-text-center gui-padding gui-margin-top">
			<button v-if="check" open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber" class="gui-color-white bg-lv"
				style="border-radius: 50rpx; ">
				手机号快捷登录
			</button>
		
			<button v-if="!check" class="gui-color-white bg-lv" @click="notongyui"
				style="border-radius: 50rpx; ">
				手机号快捷登录
			</button>
		
		<!-- 	<button @click="login" class="bg-lv gui-color-white gui-margin-top" style="border-radius: 50rpx;">
				微信登录
			</button> -->
		</view>
		
		
		<view class="gui-flex gui-h6 gui-margin-top">
			<view class="gui-flex1"></view>
			<view class="gui-icons gui-color-blue " @click="check=!check" style="margin: 6rpx;">
				{{ check?'&#xe7f8;':'&#xe762;' }}
			</view>
			<view> 我已阅读同意</view>
			<view class="gui-icons gui-color-blue" @click="yonghuxieyi"> 《 用户协议 》 </view>与
			<view class="gui-icons gui-color-blue"@click="yinsixieyi" >《 隐私协议 》 </view>
			<view class="gui-flex1"></view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				session_key: '',
				check: false
			}
		},
		onLoad() {
			this.wchatLogin()
		},
		methods: {
			notongyui() {
				uni.showModal({
					content: '请先同意用户协议'
				})
			
				return;
			},
			yonghuxieyi() {
				uni.navigateTo({
					url: '/pages/user/yonghuxieyi'
				})
			},
			yinsixieyi(){
				uni.navigateTo({
					url: '/pages/user/yinsixieyi'
				})
			},
			onGetPhoneNumber(e) {
				if (!this.check) {
				
					uni.showModal({
						content: '请先同意用户协议'
					})
				
					return;
				}

				if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
					//用户决绝授权  
					//拒绝授权后弹出一些提示  
				} else { 
					//允许授权 ，进行手机号解密
					let self = this
					uni.gRequest.get('wchat/phone', {
						sessionKey: self.session_key,
						encryptedData: e.detail.encryptedData,
						iv: e.detail.iv
					}).then(res => {
					
						console.log(res, '获取手机号');
						// 调用户修改手机号接口
						uni.gRequest.get('fhxmuser/update/information',{
							type: '手机号',
							information: JSON.parse(res.data).phoneNumber
						}).then(rt=>{
						
						  uni.showToast({
						        title: '登录成功',
						        icon: "none",
						        success: () => {
						            uni.switchTab({
						                url: '/pages/switchPages/home'
						            });
						        }
						    });				
						})
					})
				}
			},
			login() {
			
				if (!this.check) {
			
					uni.showModal({
						content: '请先同意用户协议'
					})
			
					return;
				}
			
				uni.switchTab({
					url: '/pages/switchPages/index'
				})
			},
			wchatLogin() {
				
				//处理推广人
				
				var tgcode =  uni.getStorageSync("tgcode");
							
				let self = this
				uni.login({
					provider: 'weixin',
					success(res) {
						uni.gRequest.get("wchat/login", {
							code: res.code,
							tgcode:tgcode
						}).then(result => {
							
							self.session_key = result.data.sessionKey
							uni.setStorageSync("userInfo", result.data);						
						});

					}
				})
			}
		}
	}
</script>

<style>

</style>